function [dat, trialsummary] = rick_read_trace(filename)

fid = fopen(filename, 'r');

cline = fgetl(fid);

trialsummary = struct('block',0,'trial',[],'subject',[],'experiment',[],...
    'fpc',[],'occ_x',[],'occ_w',[],'fixation',[],'stimuli',[]);

while isempty(regexp(cline, 'MSG.*BLOCK', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %f');
trialsummary.block = temp{4};

while isempty(regexp(cline, 'MSG.*TRIAL', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %f');
trialsummary.trial = temp{4};

while isempty(regexp(cline, 'MSG.*SUBJECT', 'ONCE'))
  cline = fgetl(fid);
end

temp = textscan(cline, '%s %u %s %f');
trialsummary.subject = temp{4};

while isempty(regexp(cline, 'MSG.*EXPERIMENT', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %f');
trialsummary.experiment = temp{4};

while isempty(regexp(cline, 'MSG.*FPC', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %f');
trialsummary.fpc = temp{4};

while isempty(regexp(cline, 'MSG.*OCC_X', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %f');
trialsummary.occ_x = temp{4};

while isempty(regexp(cline, 'MSG.*OCC_W', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %f');
trialsummary.occ_w = temp{4};

while isempty(regexp(cline, 'MSG.*FIXATION', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %f');
trialsummary.fixation = temp{4};

while isempty(regexp(cline, 'MSG.*STIMULI', 'ONCE'))
  cline = fgetl(fid);
end
temp = textscan(cline, '%s %u %s %s');
trialsummary.block = temp{4};

while isempty(regexp(fgetl(fid), 'MSG.*START', 'ONCE')); end;

dat = [];
cline = fgetl(fid);
sac = 0;
while isempty(regexp(cline, 'MSG.*END', 'ONCE'))
    cline = fgetl(fid);
    if ~isempty(regexp(cline, 'SSACC','ONCE'))
        sac = 1;
    elseif ~isempty(regexp(cline, 'SFIX','ONCE'))
        sac = 0;
    elseif ~isempty(str2num(strrep(cline, '...', '')))
        dat = [dat; str2num(strrep(cline, '...', '')), sac];
    end
    %   if strncmp('EFIX', cline, 4)
    %
    %   end
    %   dat = [dat; str2num(strrep(cline, '...', ''))];
    %   cline = fgetl(fid);
end


fclose(fid);
%%